<template>
  <div class="app-container">
    <el-card class="btnTop">
      <el-button-group>
        <el-button type="primary" size="mini" @click="downPdf">生成</el-button>
        <el-button type="primary" size="mini" @click="savePdf">保存</el-button>
        <el-button type="primary" size="mini" @click="back">返回</el-button>
      </el-button-group>
    </el-card>
    <el-card>
      <div id="pdfBox" ref="pdfBox" class="pdfbox">
        <PdfPage :ids="ids" :num="2" />
      </div>
    </el-card>
    <el-button
      style="display: none"
      :plain="true"
      @click="open2"
    >成功</el-button>
  </div>
</template>

<script>
import htmlToPdf from '@/utils/htmlToPdf'
import PdfPage from './components/PdfPage'

export default {
  name: 'index',
  components: {
    PdfPage
  },
  data() {
    return {
      ids: ''
    }
  },
  created() {
    this.ids = this.$route.query.id
    console.log('接收的参数', this.$route.query.id)
  },
  methods: {
    open2() {
      this.$message({
        message: '保存成功',
        type: 'success'
      })
    },
    // 保存pdf
    savePdf() {
      this.open2()
    },
    // 返回
    back() {
      this.$router.go(-1)
    },
    /**
     * @description: 打印PDF
     * @author: hst
     */
    downPdf() {
      htmlToPdf.downloadPDF(this.$refs.pdfBox, '我的PDF', this.ids)
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  position: relative;
  padding-top: 70px;
}

.pdfbox {
  width: 1000px;
  margin: 0 auto;
  border: 1px solid #000;
}

.btnTop {
  position: fixed;
  right: 0;
  top: 0;
  display: flex;
  justify-content: flex-end;
  width: 100%;
  height: 70px;
  z-index: 10;
}
</style>
